/*
 * @Author: your name
 * @Date: 2021-03-29 16:37:55
 * @LastEditTime: 2021-04-22 15:43:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \active-front\src\store\index.js
 */
import Vue from "vue";
import Vuex from "vuex";
import user from "./user";

Vue.use(Vuex);

export default new Vuex.Store({
  //全局状态
  state: {
    //头部导航栏默认值
    activeIndex: "/info/home",
    //侧边导航栏默认值
    navmenuIndex: "1",
    //头像
    ImgUrl: "",
    //消息数据
    news: null,
    maxNews: null
  },
  //同步方法
  mutations: {
    //动态改变导航栏 主要用于浏览器地址栏回车后改变
    activeIndexUpdate: (state, payload) => (state.activeIndex = payload),
    navmenuIndexUpdate: (state, payload) => (state.navmenuIndex = payload),
    UpdateImgUrl: (state, payload) => (state.ImgUrl = payload),
    UpdateNews: (state, payload) => {
      let num = 0;
      payload.map(item => {
        num += item.num;
      });
      state.news = payload;
      state.maxNews = num;
    }
  },
  //异步方法
  actions: {},
  //计算
  getters: {},
  //模块
  modules: {
    user
  }
});
